layui.config({
	base : "js/"
}).use(['form','layer','jquery','laypage'],function(){
	var form = layui.form(),
		layer = parent.layer === undefined ? layui.layer : parent.layer,
		laypage = layui.laypage,
		$ = layui.jquery;

	//模糊查询

	$("#search_btn1").click(function(){
		var text=$("#sell_text1").val()
		var newArray = [];
		if($(".search_input").val() != ''){
			var index = layer.msg('查询中，请稍候',{icon: 16,time:false,shade:0.8});
            setTimeout(function(){
            	$.ajax({
					url:"../../sell/tolikeseek",
					type:"get",
					data:"text="+ text,
					dataType : "json",
					success : function(res){
						//循环遍历符合条件的员工的信息
						var str = "";
						for (i = 0; i < res.data.length; i++) {
							str += "<tr>\n" +
								"\t\t\t\t\t\t\t<td><input name=\"checked\" lay-skin=\"primary\" lay-filter=\"choose\" type=\"checkbox\" value='" + res.data[i].id + "'>\n" +
								"\t\t\t\t\t\t\t\t<div class=\"layui-unselect layui-form-checkbox\" lay-skin=\"primary\"><i class=\"layui-icon\"></i></div>\n" +
								"\t\t\t\t\t\t\t</td>"
							str += "<td align=\"center\">" + res.data[i].odd + "</td>";
							str += "<td>" +new Date(res.data[i].selltime).toLocaleString() + "</td>";
							str += "<td>" + res.data[i].sumprice + "</td>";
							str += "<td>" + res.data[i].principal + "</td>";
							str += "<td>" + res.data[i].remark + "</td>";
							str += "<td>\n" +
								"\t\t\t\t\t\t\t<a class=\"layui-btn layui-btn-mini news_edit\" onclick=\"toupdate(" + res.data[i].id + ")\"><i class=\"iconfont icon-edit\"></i> 编辑</a>\n" +
								"\t\t\t\t\t\t\t<a class=\"layui-btn layui-btn-danger layui-btn-mini news_del\" data-id=\"6\" onclick=\"toremove(" + res.data[i].id + ")\"><i class=\"layui-icon\"></i> 删除</a>\n" +
								"\t\t\t\t\t\t</td>";



							layui.use(['form', 'upload'], function () {
								var form = layui.form();
								form.render();
							})
						}


						$("#cxtable").html(str);
						/*重新渲染*/
						layui.use(['form','upload'],function() {
							var form = layui.form();
							form.render();
						})



					}
				})
            	
                layer.close(index);
            },2000);
		}else{
			layer.msg("请输入需要查询的内容");
		}
	})



	//添加员工操作
	//改变窗口大小时，重置弹窗的高度，防止超出可视区域（如F12调出debug的操作）
	$(window).one("resize",function(){
		$("#addsell").click(function(){
			var index = layui.layer.open({
				title : "添加员工",
				type : 2,
				content : "sellinfo.html",
				success : function(layero, index){
					setTimeout(function(){
						layui.layer.tips('点击此处返回供货商列表', '.layui-layer-setwin .layui-layer-close', {
							tips: 3
						});
					},500)



				}
			})			
			layui.layer.full(index);
		})
	}).resize();



	//全选
	form.on('checkbox(allChoose)', function(data){
		var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]:not([name="show"])');
		child.each(function(index, item){
			item.checked = data.elem.checked;
		});
		form.render('checkbox');
	});

})
